<html>
  <head>
    <title>高阶函数 函数柯里化</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="text/javascript" src="../../js/react.development.js"></script>
    <script type="text/javascript" src="../../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../../js/babel.min.js"></script>
    <script type="text/babel">
      class Login extends React.Component {
        state = {
          username: '',
          password: '',
        }

        handleInputChange = (field) => {
          return (event) => {
            this.setState({ [field]: event.target.value });
          }
        }

        onSubmit = (event) => {
          event.preventDefault();
          const { username, password } = this.state;
          console.log(`你输入的用户名是: ${username}，密码是: ${password}`);
        }

        render() {
          return (
            <form onSubmit={this.onSubmit}>
              用户名：<input onChange={this.handleInputChange('username')} type="text" placeholder="用户名" /> &nbsp;
              密码：<input onChange={this.handleInputChange('password')} type="password" placeholder="密码" /> &nbsp;
              <button>登录</button>
            </form>
          );
        }
      }
      ReactDOM.render(<Login />, document.getElementById('root'));
    </script>
  </body>
</html>
